export const wrapperEnv = (env: Record<string, string>): any => {
  const ret: any = {}

  for (const envName of Object.keys(env)) {
    let realName: any = env[envName].replace(/\\n/g, '\n')
    realName = realName === 'true' ? true : realName === 'false' ? false : realName

    ret[envName] = realName
    process.env[envName] = realName
  }
  return ret
}

// 自动导入env变量并去除 VITE_ 前缀
export const autoAliasEnv = (env: Record<string, string>): { [key in string]: string } => {
  try {
    if(!env || !Object.keys(env).length) return env
    return Object.fromEntries(Object.keys(env).map((key: any) => [key.split('VITE_')[1], JSON.stringify(env[key])]))
  } catch(err){
    throw 'autoAliasEnv error'
  }
}
